home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / newlooklib.lha / newlook / createframe.c < prev    next >
C/C++ Source or Header  |  1993-11-03  |  3KB  |  101 lines

  1. /*
  2.  *  CREATEFRAME.C
  3.  */
  4.  
  5. #include "newlook.h"
  6.  
  7. struct Border *CreateFrame(x,y,w,h,dx,dy)
  8. SHORT x,y;
  9. USHORT w,h,dx,dy;
  10. {
  11.   struct Border *b0,*b1,*l;
  12.   SHORT *xy;
  13.  
  14.   long numlines= w-dx-1;
  15.  
  16.   ULONG UserHandle= SetNewLookHandle(PRIVATE_HANDLE);
  17.  
  18.   if(b0= CreateBorder(x,y,w,h,FALSE))
  19.   {
  20.     if(b1= CreateBorder(x+dx,y+dy,w-2*dx,h-2*dy,TRUE))
  21.     {
  22.       if(l= (struct Border *)SmartAllocate( numlines * BORDERSIZE ))
  23.       {
  24.         if(xy= (SHORT *)SmartAllocate( 2*4*sizeof(SHORT)))
  25.         {
  26.           int n,xn;
  27.  
  28.           /* shared pairs for the long lines */
  29.           xy[0]= xy[1]= xy[2]= (SHORT)0L;
  30.           xy[3]= h-3;
  31.  
  32.           /* shared pairs for the short lines */
  33.           xy[4]= xy[5]= xy[6]= (SHORT)0L;
  34.           xy[7]= dy-2;
  35.  
  36.           /* place left, long lines */
  37.           for(n=0, xn=3; xn<dx; n++, xn+=2)
  38.           {
  39.             l[n].LeftEdge     = x+xn;
  40.             l[n].TopEdge      = y+1;
  41.             l[n].FrontPen     = 2L;
  42.             l[n].BackPen      = 0;
  43.             l[n].DrawMode     = JAM1;
  44.             l[n].Count        = 2;
  45.             l[n].XY           = &xy[0];
  46.             l[n].NextBorder   = &l[n+1];
  47.           }
  48.  
  49.           /* place short lines */
  50.           for(; xn<w-dx; n+=2, xn+=2)
  51.           {
  52.             /* top */
  53.             l[n].LeftEdge     = x+xn;
  54.             l[n].TopEdge      = y+1;
  55.             l[n].FrontPen     = 2L;
  56.             l[n].BackPen      = 0;
  57.             l[n].DrawMode     = JAM1;
  58.             l[n].Count        = 2;
  59.             l[n].XY           = &xy[4];
  60.             l[n].NextBorder   = &l[n+1];
  61.  
  62.             /* bottom */
  63.             l[n+1].LeftEdge   = x+xn;
  64.             l[n+1].TopEdge    = y+h-dy;
  65.             l[n+1].FrontPen   = 2L;
  66.             l[n+1].BackPen    = 0;
  67.             l[n+1].DrawMode   = JAM1;
  68.             l[n+1].Count      = 2;
  69.             l[n+1].XY         = &xy[4];
  70.             l[n+1].NextBorder = &l[n+2];
  71.           }
  72.  
  73.           /* place right, long lines */
  74.           for(; xn<w-1; n++, xn+=2)
  75.           {
  76.             l[n].LeftEdge     = x+xn;
  77.             l[n].TopEdge      = y+1;
  78.             l[n].FrontPen     = 2L;
  79.             l[n].BackPen      = 0;
  80.             l[n].DrawMode     = JAM1;
  81.             l[n].Count        = 2;
  82.             l[n].XY           = &xy[0];
  83.             l[n].NextBorder   = (xn<w-3) ? &l[n+1] : (struct Border *)NULL;
  84.           }
  85.  
  86.           LastBorder(b0)->NextBorder= b1;
  87.           LastBorder(b1)->NextBorder= &l[0];
  88.  
  89.           MakePrivateHandlePublic(UserHandle);
  90.           return b0;
  91.         }
  92.       }
  93.     }
  94.   }
  95.   if(UserHandle != PRIVATE_HANDLE)
  96.   { SmartFreeAll(PRIVATE_HANDLE);
  97.     (void)SetNewLookHandle(UserHandle);
  98.   }
  99.   return (struct Border *)NULL;
  100. }
  101.